package Prac;

import java.util.Scanner;


public class P11_29 {


    static class TreeNode {
        char val;
        TreeNode left;
        TreeNode right;

        public TreeNode(char val) {
            this.val = val;
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            TreeNode root = preorderBuildTree(in.nextLine());
            inorder(root);
        }
    }

    static int i = 0;

    public static TreeNode preorderBuildTree

            (String str) {
        char c = str.charAt(i);
        if (c == '#') {
            i++;
            return null;
        }
        TreeNode root = new TreeNode(c);
        i++;
        root.left = preorderBuildTree(str);
        root.right = preorderBuildTree(str);
        return root;
    }

    public static void inorder(TreeNode root) {
        if (root == null) {
            return;
        }
        inorder(root.left);
        System.out.print(root.val + " ");
        inorder(root.right);
    }


}
